import HttpRequest from "@/libs/axios";

const request = function request({ url, method, data, params, file }) {
    method = method ? method.toUpperCase() : "GET";
    params = params ? params : {};
    data = data ? data : {};
    if (method == "GET") {
        params = { ...params, ...data };
    }
    return new Promise((resolve, reject) => {
        let obj = {
            url: url,
            method: method,
        };
        obj.params = params;
        obj.data = data;
        obj.file = file ? file : false;
        HttpRequest(obj).then(
            (response) => {
                resolve(response);
            },
            (err) => {
                // 这里可以写入错误日志
                reject(err);
            },
        );
    });
};
export default request;
